package com.yzzrjy.controller.mainservlet.blog;

import com.yzzrjy.Service.BlogService;
import com.yzzrjy.bean.BlogInfoBean;
import com.yzzrjy.util.ResponseUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "GetBlogListServlet", value = "/getBlogList")
public class GetBlogListServlet extends HttpServlet {
    private BlogService blogService = new BlogService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String myUid = request.getParameter("myUid");
        String sex = request.getParameter("sex");
        String page = request.getParameter("page");
        if(myUid == null || sex == null || page == null){
            ResponseUtils.parameterError(response);
            return;
        }

        try {
            List<BlogInfoBean> list = blogService.getBlogList(myUid, sex, Integer.parseInt(page));
            ResponseUtils.success(response, list);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
